package topcbl.taxi;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;

public class CarTypeDialog extends Dialog {

	ImageButton iBtnCar4, iBtnCar7,iBtnCar5, iBtnAllCarType;
	OnChooseCarTypeListener mListener;

	public CarTypeDialog(Context context, int theme) {
		super(context, theme);
		// animation
		getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
		// custom dialog
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.dialog_choose_cars);
		// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
		// R.layout.driver_dialog_title);
		setTitle(getContext().getString(R.string.titleChooseCarType));
		findView();
		setOnClick();
		show();

	}

	void findView() {
		iBtnCar4 = (ImageButton) findViewById(R.id.ibtnCar4);
		iBtnCar7 = (ImageButton) findViewById(R.id.ibtnCar7);
		iBtnCar5 = (ImageButton) findViewById(R.id.ibtnCar5);
		iBtnAllCarType = (ImageButton) findViewById(R.id.ibtnAllCarType);
	}

	void setOnClick() {
		iBtnCar4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mListener != null) {
					mListener.onChoose(4);
					CarTypeDialog.this.dismiss();
				}
			}
		});

		iBtnCar7.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mListener != null) {
					mListener.onChoose(7);
					CarTypeDialog.this.dismiss();
				}
			}
		});
		iBtnCar5.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (mListener != null) {
					mListener.onChoose(5);
					CarTypeDialog.this.dismiss();
				}
			}
		});
		iBtnAllCarType.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (mListener != null) {
					mListener.onChoose(0);
					CarTypeDialog.this.dismiss();
				}				
			}
		});
	}

	public interface OnChooseCarTypeListener {
		public void onChoose(int result);
	}

	public void setOnChooseCarTypeListener(OnChooseCarTypeListener listener) {
		mListener = listener;
	}
}
